# Create your views here.
from datetime import datetime

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from .models import BlogPost as blogPost, BlogPostForm


def index(request):
    return render(request, template_name='web/index.html')


def BlogPost(request):
    allBlog = blogPost.objects.all()[:20]
    context = {'blogs': allBlog}
    return render(request, 'web/blog_post/list.html', context=context)


toAdd = lambda req: (
    render(req, 'web/blog_post/form.html', {'form': BlogPostForm()})
)


def AddBlog(request):
    if str(request.method).upper() == 'POST':
        title = request.POST.get('title')
        body = request.POST.get('body')
        blogPost(title=title, body=body, timestamp=datetime.now()).save()
    return HttpResponseRedirect('/web/blogPost')


def AceDemo(request):
    return render(request, 'web/ace/index.html')


def derail(request, question_id='34'):
    print('question_id= %d' % question_id)
    return render(request, '')


detail = lambda req, question_id='34': print('question_id= %d' % question_id)


def CodeGeneration(request):
    return None
